"""
公共方法
"""


# 登录认证装饰器
def auth(role):
    from core import admin, student, teacher

    def login_auth(func):
        def inner(*args, **kwargs):
            if role == 'admin':
                    if admin.user_info.get('user'):
                        res = func(*args, **kwargs)
                        return res
                    else:
                        admin.login()

            if role == 'student':
                if student.user_info.get('user'):
                    res = func(*args, **kwargs)
                    return res
                else:
                    student.login()

            if role == 'teacher':
                if teacher.user_info.get('user'):
                    res = func(*args, **kwargs)
                    return res
                else:
                    teacher.login()
        return inner

    return login_auth
